<div class="card">
  <div class="card-header d-flex justify-content-between align-items-center">
    <h5 class="mb-0">用户管理</h5>
    <a href="/users/add" class="btn btn-primary btn-sm">添加用户</a>
  </div>
  <div class="card-body">
    <!-- 搜索表单 -->
    <form method="GET" class="mb-4">
      <div class="row g-3">
        <div class="col-md-3">
          <input type="text" class="form-control" name="id" placeholder="ID" value="<%= searchParams.id || '' %>">
        </div>
        <div class="col-md-3">
          <input type="text" class="form-control" name="username" placeholder="用户名" value="<%= searchParams.username || '' %>">
        </div>
        <div class="col-md-3">
          <input type="text" class="form-control" name="createAt" placeholder="创建日期" value="<%= searchParams.createAt || '' %>">
        </div>
        <div class="col-md-3">
          <button type="submit" class="btn btn-primary">搜索</button>
          <a href="/users" class="btn btn-secondary">重置</a>
        </div>
      </div>
    </form>

    <!-- 用户列表 -->
    <div class="table-responsive">
      <table class="table table-striped table-hover">
        <thead>
          <tr>
            <th>ID</th>
            <th>用户名</th>
            <th>创建日期</th>
            <th>操作</th>
          </tr>
        </thead>
        <tbody>
          <% users.forEach(function(user) { %>
            <tr>
              <td><%= user.id %></td>
              <td><%= user.username %></td>
              <td><%= moment(user.createAt).format('YYYY-MM-DD HH:mm:ss') %></td>
              <td>
                <a href="/users/edit/<%= user.id %>" class="btn btn-sm btn-info">编辑</a>
                <form action="/users/delete/<%= user.id %>" method="POST" class="d-inline" onsubmit="return confirm('确定要删除吗？')">
                  <button type="submit" class="btn btn-sm btn-danger">删除</button>
                </form>
              </td>
            </tr>
          <% }); %>
        </tbody>
      </table>
    </div>

    <!-- 分页 -->
    <% if (totalPages > 1) { %>
      <nav>
        <ul class="pagination justify-content-center">
          <% for(let i = 1; i <= totalPages; i++) { %>
            <li class="page-item <%= currentPage == i ? 'active' : '' %>">
              <a class="page-link" href="?page=<%= i %>&<%= new URLSearchParams({...searchParams, page: i}).toString() %>">
                <%= i %>
              </a>
            </li>
          <% } %>
        </ul>
      </nav>
    <% } %>
  </div>
</div> 